package com.harmony.suppertiger.audio;


import ohos.app.Context;
import ohos.media.audio.AudioManager;
import ohos.media.audio.SoundPlayer;

/**
 * 音效：Created by Miaolonglong on 2021/12/30.
 */
public class MySoundPool {

    private Context mContext;
	private SoundPlayer mSoundPool;
    private int hitbrickSound;
    private int coinSound;
    private int hurryUpSound;
    private int hitEnemySound;
    private int jumpSound;
    private int cannotbreakSound;
    private int hurtSound;
    private int cannonSound;
    private int transferSound;
    private int brokenSound;

    public int getBrokenSound() {
        return brokenSound;
    }

    public int getTransferSound() {
        return transferSound;
    }

    public int getCannonSound() {
        return cannonSound;
    }

    public int getHurtSound() {
        return hurtSound;
    }

    public int getCannotbreakSound() {
        return cannotbreakSound;
    }

    private int itemSound;

	public int getHitEnemySound() {
		return hitEnemySound;
	}
	
	public int getJumpSound() {
		return jumpSound;
	}
	
	public int getHurryUpSound() {
		return hurryUpSound;
	}
	
	public int getCoinSound() {
		return coinSound;
	}
	
	public int getHitbrickSound() {
		return hitbrickSound;
	}

	
	public int getItemSound() {
		return itemSound;
	}
	

	
	public MySoundPool(Context mContext) {
		super();
		this.mContext = mContext;
		mSoundPool = new SoundPlayer(AudioManager.AudioVolumeType.STREAM_MUSIC.getValue());
        cannotbreakSound =getSoundId("base/media/cannotbreak.mp3");
//		itemSound = getSoundId("base/media/mushroom.mp3");
		itemSound = getSoundId("base/media/duang.mp3");
		hitbrickSound = getSoundId("base/media/duang.mp3");
		coinSound = getSoundId("base/media/coin.mp3");
		hurryUpSound = getSoundId("base/media/hurryup.mp3");
		jumpSound = getSoundId("base/media/jump.mp3");
		hitEnemySound = getSoundId("base/media/hitenemy.mp3");
        hurtSound = getSoundId("base/media/hurt.mp3");
        cannonSound = getSoundId("base/media/cannon.mp3");
        transferSound = getSoundId("base/media/transfer.mp3");
        brokenSound = getSoundId("base/media/broken.mp3");


    }
	
	public void play(int soundID){
		mSoundPool.setOnCreateCompleteListener((soundPlayer1, cacheId, status) -> {
			// 步骤3：短音播放，设置音量、循环次数和播放速度
			if (status == 0) {
				int taskId = mSoundPool.play(cacheId);
				mSoundPool.setVolume(taskId, 1.0f);
				mSoundPool.setLoop(taskId, -1); // “-1”表示一直循环播放
				mSoundPool.setPlaySpeedRate(taskId, 1.0f);
			}
		});
		// 步骤4：释放短音资源
		mSoundPool.deleteSound(soundID);
	}
	
	public int getSoundId(String fileName){
		int soundId = mSoundPool.createSound(fileName);
		return soundId;
	}
}
